import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:xlp_github_app_flutter/common/style/app_style.dart';
import 'package:xlp_github_app_flutter/common/utils/navigator_utils.dart';
import 'package:xlp_github_app_flutter/redux/app_state.dart';
import 'package:xlp_github_app_flutter/widget/diff_scale_text.dart';

/// 欢迎页
class WelcomePage extends StatefulWidget {
  static const String sName = "/";

  const WelcomePage({super.key});

  @override
  State<WelcomePage> createState() => _WelcomePageState();
}

class _WelcomePageState extends State<WelcomePage> {
  bool hadInit = false;

  String text = "";
  double fontSize = 76;

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    if (hadInit) {
      return;
    }
    hadInit = true;

    Future.delayed(const Duration(milliseconds: 500), () {
      setState(() {
        text = "Welcome";
        fontSize = 60;
      });
    });

    Future.delayed(const Duration(seconds: 1, milliseconds: 500), () {
      setState(() {
        text = "XLPGithubApp";
        fontSize = 60;
      });
    });

    Future.delayed(const Duration(seconds: 3, milliseconds: 500), () {
      if (!mounted) return; // 检查 mounted 状态
      NavigatorUtils.goMain(context);
    });
  }

  @override
  Widget build(BuildContext context) {
    return StoreBuilder<AppState>(builder: (context, store) {
      double size = 200;
      return Material(
        child: Container(
          color: AppColors.white,
          child: Stack(
            children: <Widget>[
              const Center(
                child: Image(image: AssetImage('static/images/welcome.png')),
              ),
              Align(
                alignment: const Alignment(0.0, 0.3),
                child: DiffScaleText(
                  text: text,
                  textStyle: GoogleFonts.akronim().copyWith(
                    color: AppColors.primaryDarkValue,
                    fontSize: fontSize,
                  ),
                ),
              ),
            ],
          ),
        ),
      );
    });
  }
}
